package com.cskaoyan.controller;

import com.cskaoyan.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author stone
 * @date 2022/06/01 09:48
 */
@RestController
public class UserController {

    // localhost:8080/login1?username=songge&password=niupi
    @RequestMapping("login1")
    public User login1(User user) {
        return user;
    }

    @Autowired
    ConfigurableConversionService conversionService;

    // 请求参数名叫user、Handler方法的形参名也叫user
    // SpringMVC在处理形参的过程中，就会找String → User的Converter，
    // SpringMVC并没有提供这样的Converter，我们可以自己来提供自定义的转换器，将字符串String转换user对象
    // localhost:8080/login2?user=songge
    @RequestMapping("login2")
    public User login2(User user) {
        return user;
    }
}
